package com.jlu.springsecurity.controller;

import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class LoginController {

  @RequestMapping("login")
  public String login(){

    System.out.println("ok");
    return "redirect:main.html";
  }

//  @Secured("ROLE_abc")
//  与配置类不同，PreAuthorize可以不写ROLE_
  @PreAuthorize("hasRole('ROLE_abc')")
  @RequestMapping("toMain")
  public String toMain(){
    System.out.println("ok");
    return "redirect:main.html";
  }

  @RequestMapping("toError")
  public String toError(){
    System.out.println("error");
    return "redirect:error.html";
  }

  @RequestMapping("main1")
  public String main1(){
    System.out.println("main1");
    return "redirect:main1.html";
  }

  @RequestMapping("main2")
  public String main2(){
    System.out.println("main2");
    return "redirect:main2.html";
  }

  @RequestMapping("demo")
  public String demo(){
    return "demo";
  }
  @RequestMapping("showLogin")
  public String showLogin(){
    return "login";
  }
}
